const { exec, escape } = require('../db/mysql');
const { genPassword } = require('../utils/cryp');

const login = (username, password) => {
    username = escape(username);

    // 生成加密密码
    password = genPassword(password);
    password = escape(password);

    const sql = `
        select username,realname,name from t_user,t_role,user_role where username=${username} and password=${password} and t_user.id = user_role.user_id and user_role.role_id = t_role.id
    `;
    return exec(sql).then(rows => {
        return rows[0] || {}
    })
};

module.exports = {
    login
};